package week05.necessary.jdbc;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import week05.necessary.jdbc.base.AbstractJdbcExampleImpl;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Hikari连接池
 */
public class HikariJdbcOperator extends AbstractJdbcExampleImpl {
    private static final HikariDataSource dataSource;

    static {
        HikariConfig config = new HikariConfig();
        config.setJdbcUrl(MYSQL_URL);
        config.setUsername(MYSQL_USER);
        config.setPassword(MYSQL_PASSWORD);
        dataSource = new HikariDataSource(config);
    }

    @Override
    public void executeWithTransaction(String... sql) throws SQLException {
        throw new RuntimeException("not support operate");
    }

    @Override
    public Connection getConnection() throws SQLException {
        return dataSource.getConnection();
    }
}
